package de.haw.HES.Kundenmanagement.services;

import java.security.InvalidParameterException;
import java.util.List;

import de.haw.HES.Datentypen.AdresseTyp;
import de.haw.HES.Datentypen.KundeId;
import de.haw.HES.Datentypen.KundenTyp;
import de.haw.HES.Kundenmanagement.Kunde;
import de.haw.HES.base.ApplicationContextProvider;
import de.haw.HES.base.PersistenceManager;

public class KundenmanagementAdapterServiceImpl implements
		de.haw.HES.Kundenmanagement.pub.KundenmanagementAdapterService {
	
	private PersistenceManager persistenceManager;
	
	

	public void setPersistenceManager(PersistenceManager persistence) {
		this.persistenceManager = persistence;
	}

	@Override
	public Kunde getKundeById(KundeId id) {
		
		List<Kunde> kundenList = persistenceManager.find(new Kunde(),Kunde.class.getName());
		for(Kunde current : kundenList) {
			KundeId currentId = new KundeId(current.getId());
			if(currentId.getId().equals(id.getId())) {
				return current;
//				AdresseTyp adress = createAdress(current);
//				KundenTyp result = new KundenTyp(current.getId(), current.getName(), adress);
//				return result;
			}
		}
		
		throw new InvalidParameterException();
	}
	
	private AdresseTyp createAdress(Kunde kunde) {
		AdresseTyp a = new AdresseTyp(kunde.getStreet(), kunde.getPlz(), kunde.getOrt(), kunde.getLand());
		return a;
	}

	@Override
	public List<Kunde> getKundenByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

}
